import Vue from "vue";

export default {
  async getOssPicture( picFile ) {
    let avatarUrl = "";
    // 上传部分
    let data = new FormData();
    data.append('file', picFile);
    Vue.prototype.$axios({
      url:'/oss',
      method: 'post',
      data,
      headers: {},
      //原生获取上传进度的事件
      onUploadProgress: function(progressEvent) {
        let complete = (progressEvent.loaded / progressEvent.total * 100 | 0) + '%';
        console.log('上传 ' + complete);
      }
    }).then(res => {
      var jsonString = JSON.stringify(res.data);
      var jsonObj = JSON.parse(jsonString);
      avatarUrl = jsonObj.data.url;
      return avatarUrl;
    }).catch(err => {
      console.log(err)
    });
  },
}
